package org.ry.camera.tools;

import org.ry.camera.R;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.PopupWindow;

public class LodingTool {
	
	private static PopupWindow mPopupWindow;
	
	private static LayoutInflater mInflater;
	
	private static PopupWindow getInstance(Context mContext){
		if(mPopupWindow == null){
			mPopupWindow = new PopupWindow(mContext);
		}
		if(mInflater == null){
			mInflater = LayoutInflater.from(mContext);
		}
		return mPopupWindow;
	}
	
	public static void startLoding(Context mContext,View mParent){
		PopupWindow mPopupWindow = getInstance(mContext);
		mPopupWindow.setContentView(mInflater.inflate(R.layout.popup_load,null));
		mPopupWindow.setWidth(LayoutParams.WRAP_CONTENT);
		mPopupWindow.setHeight(LayoutParams.WRAP_CONTENT);
		mPopupWindow.showAtLocation(mParent, Gravity.CENTER,0,0);
	}
	
	public static void cancelLoding(){
		if(mPopupWindow != null && mPopupWindow.isShowing()){
			mPopupWindow.dismiss();
			mPopupWindow = null;
		}
	}
	
}
